package com.project.springboot.controller;

import com.gitee.yongzhuzl.commonutil.util.map.MapUtil;
import com.gitee.yongzhuzl.commonutil.util.result.ResponseResult;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * description: 测试Controller
 * @author 朱正磊
 * @date 2022-12-08 22:46:40
 */
@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * description: 测试GetParams
     * @author 朱正磊
     * @date 2022-12-08 22:50:51
     * @param request 请求对象
     * @return 返回响应对象
     */
    @GetMapping("/testGetParams")
    public ResponseResult<String> testGetParams(HttpServletRequest request) {
        Map<String, Object> paramsMap = MapUtil.getParamsMap(request);

        String name = paramsMap.get("name").toString();
        //
        System.out.println("name = " + name);

        Integer age = Integer.valueOf(paramsMap.get("age").toString());
        //
        System.out.println("age = " + age);

        String sex = paramsMap.get("sex").toString();
        //
        System.out.println("sex = " + sex);

        //======================================================================================//

        Map<String, String> paramsMapValueStr = MapUtil.getParamsMapValueStr(request);

        String name1 = paramsMapValueStr.get("name");
        //
        System.out.println("name1 = " + name1);

        String age1 = paramsMapValueStr.get("age");
        //
        System.out.println("age1 = " + age1);

        String sex1 = paramsMapValueStr.get("sex");
        //
        System.out.println("sex1 = " + sex1);

        return ResponseResult.buildSuccess("测试testGetParam成功");
    }

    /**
     * description: 测试PostParams
     * @author 朱正磊
     * @date 2022-12-08 22:50:56
     * @param request 请求对象
     * @return 返回响应对象
     */
    @PostMapping("/testPostParams")
    public ResponseResult<String> testPostParams(HttpServletRequest request) {
        Map<String, Object> paramsMap = MapUtil.getParamsMap(request);

        String name = paramsMap.get("name").toString();
        //
        System.out.println("name = " + name);

        Integer age = Integer.valueOf(paramsMap.get("age").toString());
        //
        System.out.println("age = " + age);

        String sex = paramsMap.get("sex").toString();
        //
        System.out.println("sex = " + sex);

        //======================================================================================//

        Map<String, String> paramsMapValueStr = MapUtil.getParamsMapValueStr(request);

        String name1 = paramsMapValueStr.get("name");
        //
        System.out.println("name1 = " + name1);

        String age1 = paramsMapValueStr.get("age");
        //
        System.out.println("age1 = " + age1);

        String sex1 = paramsMapValueStr.get("sex");
        //
        System.out.println("sex1 = " + sex1);

        return ResponseResult.buildSuccess("测试testPostParam成功");
    }

    /**
     * description: 测试PostForm
     * @author 朱正磊
     * @date 2022-12-08 22:50:56
     * @param request 请求对象
     * @return 返回响应对象
     */
    @PostMapping("/testPostForm")
    public ResponseResult<String> testPostForm(HttpServletRequest request) {
        Map<String, Object> paramsMap = MapUtil.getParamsMap(request);

        String name = paramsMap.get("name").toString();
        //
        System.out.println("name = " + name);

        Integer age = Integer.valueOf(paramsMap.get("age").toString());
        //
        System.out.println("age = " + age);

        String sex = paramsMap.get("sex").toString();
        //
        System.out.println("sex = " + sex);

        //======================================================================================//

        Map<String, String> paramsMapValueStr = MapUtil.getParamsMapValueStr(request);

        String name1 = paramsMapValueStr.get("name");
        //
        System.out.println("name1 = " + name1);

        String age1 = paramsMapValueStr.get("age");
        //
        System.out.println("age1 = " + age1);

        String sex1 = paramsMapValueStr.get("sex");
        //
        System.out.println("sex1 = " + sex1);

        return ResponseResult.buildSuccess("测试testPostForm成功");
    }

    /**
     * description: 测试PostJson
     * @author 朱正磊
     * @date 2022-12-08 22:50:56
     * @param request 请求对象
     * @return 返回响应对象
     */
    @PostMapping("/testPostJson")
    public ResponseResult<String> testPostJson(HttpServletRequest request) {
//        Map<String, Object> paramsMap = MapUtil.getParamsMap(request);
//
//        String name = (String) paramsMap.get("name");
//        //
//        System.out.println("name = " + name);
//
//        Integer age = (Integer) paramsMap.get("age");
//        //
//        System.out.println("age = " + age);
//
//        String sex = (String) paramsMap.get("sex");
//        //
//        System.out.println("sex = " + sex);

        //======================================================================================//

        Map<String, String> paramsMapValueStr = MapUtil.getParamsMapValueStr(request);

        String name1 = paramsMapValueStr.get("name");
        //
        System.out.println("name1 = " + name1);

        String age1 = paramsMapValueStr.get("age");
        //
        System.out.println("age1 = " + age1);

        String sex1 = paramsMapValueStr.get("sex");
        //
        System.out.println("sex1 = " + sex1);

        return ResponseResult.buildSuccess("测试testPostJson成功");
    }

    /**
     * description: 测试PostXml
     * @author 朱正磊
     * @date 2022-12-08 22:50:56
     * @param request 请求对象
     * @return 返回响应对象
     */
    @PostMapping("/testPostXml")
    public ResponseResult<String> testPostXml(HttpServletRequest request) {
//        Map<String, Object> paramsMap = MapUtil.getParamsMap(request);
//
//        String name = paramsMap.get("name").toString();
//        //
//        System.out.println("name = " + name);
//
//        Integer age = Integer.valueOf(paramsMap.get("age").toString());
//        //
//        System.out.println("age = " + age);
//
//        String sex = paramsMap.get("sex").toString();
//        //
//        System.out.println("sex = " + sex);

        //======================================================================================//

        Map<String, String> paramsMapValueStr = MapUtil.getParamsMapValueStr(request);

        String name1 = paramsMapValueStr.get("name");
        //
        System.out.println("name1 = " + name1);

        String age1 = paramsMapValueStr.get("age");
        //
        System.out.println("age1 = " + age1);

        String sex1 = paramsMapValueStr.get("sex");
        //
        System.out.println("sex1 = " + sex1);

        return ResponseResult.buildSuccess("测试testPostXml成功");
    }

}
